/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mas.server;

import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Properties;
import mas.shared.Request;
import mas.shared.ResponseCommand;
import mas.shared.impl.ResponseImpl;
import mas.shared.utils.RequestHandler;
import mas.shared.utils.Utils;

/**
 * This is the server.
 *
 */
public class Server
{
    /**
     * Start the server.
     * @param args command line arguments
     */
    public static void main(String[] args) throws Exception
    {
        System.err.println("Server running.");
        System.err.println("CWD: " + System.getProperty("user.dir"));
        
        Properties serverProps = Utils.loadPropertiesFile("server.properties");
        ServerSocket serverSocket = new ServerSocket(Integer.parseInt(serverProps.getProperty("server.port")));
        
        for (;;)
        {
            System.err.println("Waiting for request...");
            Socket clientSocket = serverSocket.accept();
            RequestHandler rh = new RequestHandler(clientSocket);
            new CommandHandler(rh).start();
        }
    }    
}
